#include "PreviewDirectionSelector.h"
#include "ui_PreviewDirectionSelector.h"

PreviewDirectionSelector::PreviewDirectionSelector(std::shared_ptr<ViewCamera> parent)
    : m_sptr_viewCamera(parent)
    , ui(new Ui::PreviewDirectionSelector)
{
    ui->setupUi(this);
    m_original_model_pos = m_sptr_viewCamera->getEye();
    m_original_model_center = m_sptr_viewCamera->getCenter();
    m_original_model_up = m_sptr_viewCamera->getUp();
    m_latest_model_pos = m_sptr_viewCamera->getEye();
    m_latest_model_center = m_sptr_viewCamera->getCenter();
    m_latest_model_up = m_sptr_viewCamera->getUp();
};

PreviewDirectionSelector::~PreviewDirectionSelector()
{
    delete ui;
}

void PreviewDirectionSelector::on_left_top_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::D1, 90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_right_bottom_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::D1, -90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_left_bottom_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::D2, 90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_right_top_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::D2, -90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_left_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::X, 90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_right_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::X, -90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_bottom_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::Y, -90);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_top_clicked()
{
    m_sptr_viewCamera->surroundOriginThroughFixDirection(FixDirection::Y, 90);
    emit updateCameraView();
}

void PreviewDirectionSelector::on_model_recover_clicked()
{
    m_sptr_viewCamera->lookAt(m_latest_model_pos, m_latest_model_center, m_latest_model_up);
    emit updateCameraView();
}


void PreviewDirectionSelector::on_record_latest_clicked()
{
    m_latest_model_pos = m_sptr_viewCamera->getEye();
    m_latest_model_center = m_sptr_viewCamera->getCenter();
    m_latest_model_up = m_sptr_viewCamera->getUp();
}


void PreviewDirectionSelector::on_recover_origin_clicked()
{
    m_sptr_viewCamera->lookAt(m_original_model_pos, m_original_model_center, m_original_model_up);
    emit updateCameraView();
}

